/*
 This file is part of WebHUD.
 
 WebHUD is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 any later version.
 
 WebHUD is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with WebHUD.  If not, see <http://www.gnu.org/licenses/>.
 */

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

#import "WHApi.h"

@interface WHController : NSObject {
    IBOutlet NSPanel        	*panel;
    IBOutlet WebView        	*webview;
    IBOutlet NSSegmentedControl *segControl;

    NSString                *mainFrameURL;
    NSMutableDictionary     *urls;
    NSMutableArray          *order;

@private
    WHApi                   *api;
    bool                    is_redirect;
    NSString                *redirectUrl;
}

@property(nonatomic, retain) IBOutlet NSPanel       *panel;
@property(nonatomic, retain) IBOutlet WebView       *webview;
@property(nonatomic, retain) IBOutlet NSSegmentedControl     *segControl;
@property(nonatomic, retain) NSMutableDictionary    *urls;
@property(nonatomic, retain) NSMutableArray         *order;
@property(retain)            NSString               *mainFrameURL;
@property(retain)            NSString               *redirectUrl;

// update HUD
- (void)updateWithFrame:(WebFrame *)frame;

// Singleton
+ (WHController*)sharedController;
+ (id)allocWithZone:(NSZone *)zone;
- (id)copyWithZone:(NSZone *)zone;
- (id)retain;
- (unsigned)retainCount;
- (void)release;
- (id)autorelease;

// frameLoadDelegate
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowObject
       forFrame:(WebFrame *)frame;
- (void)webView:(WebView *)sender didReceiveServerRedirectForProvisionalLoadForFrame:(WebFrame *)frame;

// WebPolicyDelegate methods
- (void)webView:(WebView *)sender
decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
                       request:(NSURLRequest *)request
                  newFrameName:(NSString *)frameName
              decisionListener:(id < WebPolicyDecisionListener >)listener;
- (void)webView:(WebView *)sender
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
                        request:(NSURLRequest *)request
                          frame:(WebFrame *)frame
               decisionListener:(id < WebPolicyDecisionListener >)listener;

// NSWindow delegate
- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;

// Actions
- (IBAction)segControlClicked:(id)sender;

// private HUD api
- (void)getHUDLinks:(NSMutableDictionary *)newLinks
              order:(NSMutableArray *)newOrder
          fromFrame:(WebFrame *)frame;

- (void)loadUrl:(NSString *)url;
- (void)resizeSegmentedControl;


-(void)updateTabsWithLinks:(NSMutableDictionary *)newLinks
                     order:(NSMutableArray *)newOrder
                     merge:(bool)doMerge;
@end

/* vim: set ts=4 sw=4 expandtab: */
